<?php
namespace app\index\controller;
use app\admin\model\NewsModel;
use app\admin\model\LeaseModel;
use app\admin\model\RequirementModel;
use think\Db;
use app\index\model\AdminModel;

class Index extends Base
{

    public function index(){
        $userInfo = $this->user_info;
        if($userInfo){
            $param = $this->request->param();
            $list = getSystemPair($userInfo,$this->config);
//            print_r($otherInfo);die;
            if($list){

                foreach ($list as &$v){
                    $v['range'] = getDistance($userInfo['lat'],$userInfo['lng'],$v['lat'],$v['lng']).'km';  //两者之间的距离
//                    $v['head_img'] = 'http://' . $_SERVER['SERVER_NAME'].'/uploads/face/'.$v['head_img'];
                    if($v['habit']){
                        $v['habit'] = Db('tag')->where(['id'=>['in',$v['habit']]])->column('name');
                    }
                }

            }else{
                return json(['code'=>0,'msg'=>'抱歉暂无心仪的对象']);
            }

            $articleList = Db('article')->field('id,title,photo')->select();   //滚动图
            if($articleList){
                foreach ($articleList as &$v){
                    $v['photo'] = 'http://' . $_SERVER['SERVER_NAME'].'/uploads/images/'.$v['photo'];
                }
            }
            $this->assign('list',$list);
            $this->assign('articleList',$articleList);
            return $this->fetch();

        }else{
            return json(['code'=>0,'msg'=>'数据异常']);
        }
    }

    public function clear(){
        session('user_id',0);
        return json(['code'=>0,'msg'=>'数据异常']);
    }

    public function notice(){
        $param = $this->request->param();
        $msg = $param['msg']?:'遇到错误';
        $this->assign('msg',$msg);
        return $this->fetch();
    }
    

}
